using Forecast.Database;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;

namespace Forecast.Business.IntegrationTest
{
    [TestFixture]
    public class TestPlayer
    {
        #region Variables

        private Save _save;
        private int _firstPlayerId;
        private int _predictionId;

        #endregion
        #region Setup / Teardown

        [SetUp]
        public void Setup()
        {
            _save = new Save(DatabaseSetup.GetConnectionString());
            _firstPlayerId = CreatePlayer();
            _predictionId = CreatePrediction();
        }

        [TearDown]
        public void Teardown()
        {
            _save.DeletePrediction(_predictionId);
            _save.DeletePlayer(_firstPlayerId);            
        }

        #endregion
        #region Tests

        [Test]
        public void CreateAndLoadPlayer()
        {
            Assert.AreNotSame(_firstPlayerId, -1);
        }

        [Test]
        public void CreateOffer()
        {
            Offer offer = new Offer();
            offer.EndDate = DateTime.Today.AddDays(10);
            offer.IsAccepted = false;
            offer.IsActive = true;
            offer.IsBuy = true;
            offer.NumPredictions = 10;
            offer.PlayerId = _firstPlayerId;
            offer.PredictionId = _predictionId;
            offer.Price = 28;
            _save.NewOffer(offer);
        }

        /*
        [Test]
        public void 
         * */

        #endregion
        #region Private methods

        private int CreatePlayer()
        {
            Player player = new Player();
            player.Cash = 2500;
            player.UserName = "Integration tester 007";
            int playerId = _save.NewPlayer(player);
            return playerId;
        }

        private int CreatePrediction()
        {
            Prediction prediction = new Prediction();
            prediction.EndDate = DateTime.Today.AddMonths(2);
            prediction.HasSucceeded = false;
            prediction.IsActive = true;
            prediction.IsClosed = false;
            prediction.LastChange = (decimal)(-12.12);
            prediction.LastValue = 33;
            prediction.LongDescription = "This is a prediciton for integration tests.";
            prediction.ShortDescription = "Integration test prediction";
            prediction.Ticker = "ITP";
            int predictionId = _save.NewPrediction(prediction);
            return predictionId;
        }

        #endregion
    }
}
